package sky.domain;

import org.hibernate.annotations.Type;
import org.joda.time.DateTime;
import org.joda.time.contrib.hibernate.PersistentDateTime;
import org.springframework.beans.factory.annotation.Value;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;

/**
 * Created with IntelliJ IDEA.
 * User: Gauss
 * Date: 24.04.13
 * Time: 17:00
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "flights")
public class Flight {

    @Id
    @Column(name = "id")
    @GeneratedValue
    private Integer id;

    @ManyToOne
    private Airport departureAirport;

    @ManyToOne
    private Airport destinationAirport;

    @ManyToOne
    private Plane plane;

    @Column(name = "DepartureDate")
    private Date departureDate;

    @Column(name = "DestinationDate")
    private Date destinationDate;

    public Date getDepartureDate() {
        return departureDate;
    }

    public void setDepartureDate(Date departureDate) {
        this.departureDate = departureDate;
    }

    public Date getDestinationDate() {
        return destinationDate;
    }

    public void setDestinationDate(Date destinationDate) {
        this.destinationDate = destinationDate;
    }

    @Column(name = "FreeAllPlaces")
    private Integer freeAllPlaces;

    @Column(name = "FreeEconomPlaces")
    private Integer freeEconomPlaces;

    @Column(name = "FreeBussinessPlaces")
    private Integer freeBussinessPlaces;

    @Column(name = "FreeFirstClassPlaces")
    private Integer freeFirstClassPlaces;

    public Integer getFreeAllPlaces() {
        return freeAllPlaces;
    }

    public void setFreeAllPlaces(Integer freeAllPlaces) {
        this.freeAllPlaces = freeAllPlaces;
    }

    public Integer getFreeEconomPlaces() {
        return freeEconomPlaces;
    }

    public void setFreeEconomPlaces(Integer freeEconomPlaces) {
        this.freeEconomPlaces = freeEconomPlaces;
    }

    public Integer getFreeBussinessPlaces() {
        return freeBussinessPlaces;
    }

    public void setFreeBussinessPlaces(Integer freeBussinessPlaces) {
        this.freeBussinessPlaces = freeBussinessPlaces;
    }

    public Integer getFreeFirstClassPlaces() {
        return freeFirstClassPlaces;
    }

    public void setFreeFirstClassPlaces(Integer freeFirstClassPlaces) {
        this.freeFirstClassPlaces = freeFirstClassPlaces;
    }

    @Column(name = "EconomCost")
    private Integer economCost;

    @Column(name = "BussinessCost")
    private Integer bussinessCost;

    @Column(name = "FirstClassCost")
    private Integer firstClassCost;

    public Integer getEconomCost() {
        return economCost;
    }

    public void setEconomCost(Integer economCost) {
        this.economCost = economCost;
    }

    public Integer getBussinessCost() {
        return bussinessCost;
    }

    public void setBussinessCost(Integer bussinessCost) {
        this.bussinessCost = bussinessCost;
    }

    public Integer getFirstClassCost() {
        return firstClassCost;
    }

    public void setFirstClassCost(Integer firstClassCost) {
        this.firstClassCost = firstClassCost;
    }

    @OneToMany(mappedBy = "flight")
    @JoinColumn(name = "flight_id")
    private Set<Ticket> tickets = new HashSet<Ticket>(0);

    public Set<Ticket> getTickets() {
        return tickets;
    }

    public void setTickets(Set<Ticket> tickets) {
        this.tickets = tickets;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Airport getDepartureAirport() {
        return departureAirport;
    }

    public void setDepartureAirport(Airport departureAirport) {
        this.departureAirport = departureAirport;
    }

    public Airport getDestinationAirport() {
        return destinationAirport;
    }

    public void setDestinationAirport(Airport destinationAirport) {
        this.destinationAirport = destinationAirport;
    }

    public Plane getPlane() {
        return plane;
    }

    public void setPlane(Plane plane) {
        this.plane = plane;
    }

    public Integer getCostByType(String type) {
        if ("Econom".equals(type)) return this.economCost;
        if ("Bussiness".equals(type)) return this.bussinessCost;
        if ("FirstClass".equals(type)) return this.firstClassCost;
        return 0;
    }
}
